const path = require("path");
module.exports = {
  mode: "development",
  entry: {
    // 入口
    client: path.resolve(__dirname, "../src/client.jsx"),
  },
  output: {
    // 输出
    filename: "[name].bundle.js",
    path: path.resolve(__dirname, "../dist"),
    clean: true,
    publicPath: "/",
  },
  resolve: {
    extensions: [".jsx", ".js", ".json"],
  },
  devServer: {
    static: "./dist",
    hot: true,
  },
  module: {
    rules: [
      {
        test: /.jsx$/,
        include: [
          path.resolve(__dirname, "../src"),
        ],
        use: {
          loader: "babel-loader",
          options: {
            presets: [
              [
                "@babel/preset-env",
                {
                  useBuiltIns: "usage", // 自动加载，按需引入
                  corejs: { version: "3", proposals: true },
                },
              ],
              "@babel/preset-react",
            ],
          },
        },
      },
      {
        test: /.css$/,
        use: ["style-loader", "css-loader"],
      },
      {
        test: /.less$/,
        use: ["style-loader", "css-loader", "less-loader"],
      },
      {
        test: /.(png|svg|jpg|jpeg|gif)$/,
        type: "asset/resource",
      },
    ],
  },
};
